/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ep.m002.ui.views;

import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Component;
import ep.libs.implementations.AbstractModule;
import ep.m003.module.M003Module;
import ep.m004.module.M004Module;
import ep.m005.module.M005Module;
import ep.m006.module.M006Module;

/**
 *
 * @author Spyros
 */
public class M002DoctorView extends M002View {

    public static final String CAPTION_RECORD = "Ιατρικός Φάκελος";
    public static final String CAPTION_MEDICINE = "Ιστορικό Φαρμάκων";
    public static final String CAPTION_NEWPRESC = "Νέα Συνταγή";
    public static final String CAPTION_PENDING_PRESC = "Προβολή Συνταγών";
    private Button recordButton;
    private Button medicineButton;
    private Button newPrescButton;
    private Button viewPendingPrescButton;

    public M002DoctorView(AbstractModule module) {
        super(module);
    }

    public M002DoctorView(AbstractModule module, Object[] args) {
        super(module, args);
    }

    @Override
    protected void initilizeComponents() {
        super.initilizeComponents();
        recordButton = new Button(CAPTION_RECORD);
        medicineButton = new Button(CAPTION_MEDICINE);
        viewPendingPrescButton = new Button(CAPTION_PENDING_PRESC);
        newPrescButton = new Button(CAPTION_NEWPRESC);

        getButtonsLayout().addComponent(recordButton);
        getButtonsLayout().addComponent(medicineButton);
        getButtonsLayout().addComponent(viewPendingPrescButton);
        getButtonsLayout().addComponent(newPrescButton);

    }

    @Override
    protected void initializeListeners() {
        super.initializeListeners();
        newPrescButton.addListener(new Button.ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                module.getApplication().changeModule(M005Module.class, new Object[]{getController().getPatient()});
            }
        });

        medicineButton.addListener(new Button.ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                module.getApplication().changeModule(M004Module.class, new Object[]{getController().getPatient()});
            }
        });

        recordButton.addListener(new Button.ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                module.getApplication().changeModule(M003Module.class, new Object[]{getController().getPatient()});
            }
        });

        viewPendingPrescButton.addListener(new Button.ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                module.getApplication().changeModule(M006Module.class, new Object[]{getController().getPatient()});
            }
        });
    }

    @Override
    protected void initializeResult() {
        super.initializeResult();
        try {
            if (controller.isDoctorEligible()) {
                getButtonsLayout().setEnabled(true);
                newPrescButton.setDescription("");
            } else {
                getButtonsLayout().setEnabled(false);
                newPrescButton.setDescription("Μη συμβεβλημένη ασφάλιση");
            }
        } catch (Exception e) {
            getButtonsLayout().setEnabled(true);
        }
    }
}
